use crate::${{moduleName}}::domain::mapper::${{moduleName}}_${{business_name}}::${{className}};
use macros::page_request;
use rbatis::object_id::ObjectId;
use serde::{Deserialize, Serialize};
{% for use in useList %}
use ${{use}};
{% endfor %}

#[page_request(params)]
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct ${{className}}PageDTO {
{% for column in columns %}
{% if column.isList %}
      // ${{column.columnComment}}
    pub ${{column.columnName}}:Option<${{column.javaType}}>,
{% endif %}
{% endfor %}
}


#[derive(Serialize, Deserialize,validator::Validate, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ${{className}}AddDTO {
{% for column in columns %}
  {% if column.isInsert and not column.isPk and not column.special%}
      // ${{column.columnComment}}
    {% if column.isRequired %}
      {% if column.javaType=="String" %}
      #[validate(custom(function = "crate::string_required", message = "${{column.comment}}不能为空"))]
      {% else %}
      #[validate(required(message = "${{column.comment}}不能为空"))]
      {% endif %}
    {% endif %}
    {% if column.javaType=="String" and column.more["checkLength"]=="1" and column.maxLength>0 %}
  #[validate(length(max = ${{ column.maxLength}}, message = "${{column.comment}}不能超过${{column.maxLength}}个字符"))]
    {% endif %}
{#{% if column.javaType=="BigDecimal" %}#}
{#    @Digits(integer = column.maxLength, fraction =column.precision, message = "${column.comment}输入错误，整数长度最长为column.maxLength{% if column.precision>0 %}，小数点长度最长为column.precision{% endif %}" %}#}
{#{% elif column.max&&(column.javaType=="Integer"||column.javaType=="Long" %} %}#}
{#    @Min(value = column.min,message =  "${column.comment}不能小于column.min" %}#}
{#    @Max(value = ${column.max}{% if column.javaType=="Long" %}l{% endif %},message = "${column.comment}不能大于column.max" %}#}
{#{% endif %}#}
{#{% if column.more("pattern" %} %}#}
{#    @Pattern(regexp = "column.more("pattern" %}.replace("\","\\" %}", message = "column.more("patternMessage" %}" %}#}
{#{% endif %}#}
    pub ${{column.columnName}}:Option<${{column.javaType}}>,
  {% endif %}
{% endfor %}
}

impl From<${{className}}AddDTO> for ${{className}} {
    fn from(arg: ${{className}}AddDTO) -> Self {
        ${{className}} {
           {% if pkColumn.isIncrement %}
           ${{pkColumn.columnName}}: None,
           {% elif pkColumn.javaType=="String" %}
           ${{pkColumn.columnName}}: ObjectId::new().to_string().into(),
           {% endif %}
            {% for column in columns %} {% if not column.isPk %} {% if column.isInsert and not column.special %} ${{column.columnName}}: arg.${{column.columnName}},  {% else %}${{column.columnName}}: None,{% endif %} {% endif %} {% endfor %}
        }
    }
}

#[derive(Serialize, Deserialize,validator::Validate, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ${{className}}UpdateDTO {
 pub ${{pkColumn.columnName}}:Option<${{pkColumn.javaType}}>,
{% for column in columns %}
  {% if column.isEdit and not column.special%}
      // ${{column.columnComment}}
    {% if column.isRequired %}
      {% if column.javaType=="String" %}
      #[validate(custom(function = "crate::string_required", message = "${{column.comment}}不能为空"))]
      {% else %}
      #[validate(required(message = "${{column.comment}}不能为空"))]
      {% endif %}
    {% endif %}
    {% if column.javaType=="String" and column.more["checkLength"]=="1" and column.maxLength>0 %}
  #[validate(length(max = ${{ column.maxLength}}, message = "${{column.comment}}不能超过${{column.maxLength}}个字符"))]
    {% endif %}
{#{% if column.javaType=="BigDecimal" %}#}
{#    @Digits(integer = column.maxLength, fraction =column.precision, message = "${column.comment}输入错误，整数长度最长为column.maxLength{% if column.precision>0 %}，小数点长度最长为column.precision{% endif %}" %}#}
{#{% elif column.max&&(column.javaType=="Integer"||column.javaType=="Long" %} %}#}
{#    @Min(value = column.min,message =  "${column.comment}不能小于column.min" %}#}
{#    @Max(value = ${column.max}{% if column.javaType=="Long" %}l{% endif %},message = "${column.comment}不能大于column.max" %}#}
{#{% endif %}#}
{#{% if column.more("pattern" %} %}#}
{#    @Pattern(regexp = "column.more("pattern" %}.replace("\","\\" %}", message = "column.more("patternMessage" %}" %}#}
{#{% endif %}#}
    pub ${{column.columnName}}:Option<${{column.javaType}}>,
  {% endif %}
{% endfor %}
}

impl From<${{className}}UpdateDTO> for ${{className}} {
    fn from(arg: ${{className}}UpdateDTO) -> Self {
        ${{className}} {
            {% for column in columns %} {% if (column.isEdit or column.isPk) and not column.special%} ${{column.columnName}}: arg.${{column.columnName}}, {% else %} ${{column.columnName}}: None, {% endif %}{% endfor %}
        }
    }
}
